//
//  TeacherHeaderView.m
//  GC_OC
//
//  Created by 曾 on 2022/1/17.
//

#import "TeacherHeaderView.h"

@interface TeacherHeaderView()
@property (nonatomic, strong)NSDictionary* dic;
@end
@implementation TeacherHeaderView

-(instancetype)initWithFrame:(CGRect)frame andDic:(NSDictionary*)dic
{
    self=[super initWithFrame:frame];
    if(self)
    {
        self.dic=dic;
        NSLog(@"%@",self.dic);
        [self initView];
    }
    return self;
}
-(void)initView
{
    if(!self.dic)
    {
        return;
    }
    UIImageView* iconImg=[[UIImageView alloc]initWithFrame:CGRectMake(wid(50),wid(10),wid(165),wid(200))];
    iconImg.layer.shadowColor = RBG(200,200,200).CGColor;
    iconImg.layer.shadowOffset = CGSizeMake(0, 6); // 阴影偏移量，默认（0,0）
    iconImg.layer.shadowOpacity = 1; // 不透明度
    iconImg.backgroundColor=[UIColor lightGrayColor];
    [iconImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",server_addr,self.dic[@"teacher_image"]]] placeholderImage:[UIImage imageNamed:@""]];
    [self addSubview:iconImg];
    NSString* sex= @"保密";
    if([self.dic[@"teacher_sex"] integerValue]==1)
    {
        sex=@"男";
    }else if([self.dic[@"teacher_sex"] integerValue]==2)
    {
        sex=@"女";
    }
    NSArray* textArr=@[self.dic[@"teacher_name"],sex,@"兴趣"];
    NSArray* towArr=@[@"",[NSString stringWithFormat:@"年龄: %@",self.dic[@"teacher_age"]],[NSString stringWithFormat:@"%@",self.dic[@"teacher_phone"]]];
    for (int i=0;i<3;i++)
    {
//        UILabel* label=[UILabel alloc]initWithFrame:CGRectMake(wid(50)+wid(165)+wid(25),wid(10)+wid(200)-wid(65)*(3-i),SCREEN_WIDTH-wid(50)+wid(165)+wid(25)-wid(105),)
        UIView* lineView=[[UIView alloc]initWithFrame:CGRectMake(wid(50)+wid(165)+wid(25),wid(10)+wid(200)-wid(65)*(3-i)+wid(65)-1,SCREEN_WIDTH-(wid(50)+wid(165)+wid(25))-wid(105)-wid(25),1)];
        lineView.backgroundColor=RBG(200,200,200);
        [self addSubview:lineView];
        if(i==0)
        {
            for(int j=0;j<3;j++)
            {
                UILabel* label=[[UILabel alloc]initWithFrame:CGRectMake(lineView.frame.origin.x+lineView.frame.size.width/3.0*j,lineView.frame.origin.y-wid(65),lineView.frame.size.width/3.0,wid(65))];
                label.textColor=[UIColor blackColor];
                label.font=[UIFont systemFontOfSize:FontSize(12)];
                label.text=textArr[j];
                if(j==1)
                {
                    label.textAlignment=NSTextAlignmentCenter;
                }else if(j==2)
                {
                    label.textAlignment=NSTextAlignmentRight;
                }
                [self addSubview:label];
            }
            
        }else
        {
            UILabel* label=[[UILabel alloc]initWithFrame:CGRectMake(lineView.frame.origin.x,lineView.frame.origin.y-wid(65),lineView.frame.size.width,wid(65))];
            label.textColor=[UIColor blackColor];
            [self addSubview:label];
            if(i==2)
            {
                label.textColor=AppMainColor;
                UIButton* btn=[[UIButton alloc]initWithFrame:label.frame];
                [btn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
                [self addSubview:btn];
            }
            label.font=[UIFont systemFontOfSize:FontSize(12)];
            label.text=towArr[i];
        }
    }
}
-(void)btnAction
{
    [[UIApplication   sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",self.dic[@"teacher_phone"]]]];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
